package org.dtrd.modules.patient.entity.bean;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveBasic;
import org.dtrd.modules.archive.entity.po.DtrdEntRdArchiveBasicFamily;
import org.dtrd.modules.patient.entity.po.DtrdEntRdPatient;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * basic表 + basicFamily表 的字段
 *
 * @Author: QR
 * @Date: 2021/10/4-20:46
 */
@ApiModel("患者信息")
@Data
public class PatientBasicAndFamilyInfo {

    @ApiModelProperty("基本信息id, 查询时返回，更新时需要传入")
    private Integer dataId;

    @ApiModelProperty("患者id, 更新时需要传入")
    private Integer patientId;

    @ApiModelProperty("医生ID")
    private Integer doctorId;

    @NotBlank
    @Length(min = 7, max = 14)
    @ApiModelProperty(value = "患者电话", required = true)
    private String patientMobile;

    @NotBlank
    @Length(min = 1, max = 8)
    @ApiModelProperty(value = "患者姓名", required = true)
    private String patientName;

    @ApiModelProperty(value = "患者生日", required = true)
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date patientBirth;

    @ApiModelProperty("患者年龄")
    private Integer age;

    @ApiModelProperty(value = "患者性别: 1男2女", required = true)
    private Integer patientSex;
    @ApiModelProperty(value = "患者性别文本")
    private String patientSexText;

    @ApiModelProperty("患者证件照号")
    private String patientIdCard;

    @ApiModelProperty("确诊日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date patientConfirmedDate;

    @ApiModelProperty("起病方式")
    private String patientModeOnset;

    @ApiModelProperty("起病症状")
    private String patientSymptoms;

    @ApiModelProperty(value = "医保类型")
    private String patientMedicalInsurance;

    @ApiModelProperty("诊断结果")
    private String patientDiagnostic;

    @ApiModelProperty("糖尿病类型")
    private Integer patientDiabetisType;
    @ApiModelProperty("糖尿病类型文本")
    private String patientDiabetisTypeText;

    @ApiModelProperty("建档时间")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date recodeDate;

    @ApiModelProperty(value = "职业: 1-轻体力劳动,2-中体力劳动,3-重体力劳动", required = true)
    private Integer occupation;
    @ApiModelProperty(value = "职业文本")
    private String occupationText;

    @ApiModelProperty("文化程度：1-未读,2-小学,3-初中,4-高中,5-中专,6-大专,7-本科,8-硕士及以上")
    private Integer education;
    @ApiModelProperty("文化程度文本")
    private String educationText;

    @ApiModelProperty("所属省份")
    private Integer provinceId;
    @ApiModelProperty("省份")
    private String provinceText;

    @ApiModelProperty("所属地市")
    private Integer cityId;
    @ApiModelProperty("文本")
    private String city;

    @ApiModelProperty("长期卧床：1-是,0-否")
    private Integer isSickbed;
    @ApiModelProperty("长期卧床文本")
    private String isSickedText;

    @ApiModelProperty("患者描述")
    private String patientDesc;

    @ApiModelProperty("妊娠：1-备孕中,2-妊娠中,3-哺乳期")
    private Integer gestation;
    @ApiModelProperty("妊娠文本")
    private String gestationText;

    @ApiModelProperty("妊娠日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date gestationDate;

    @ApiModelProperty("患者属性：1-门诊,2-住院")
    private Integer patientProperty;
    @ApiModelProperty("患者属性文本")
    private String patientPropertyText;

    @ApiModelProperty(value = "医疗支付方式：1-社会医疗基本保险,2-新型农村合作医疗保险,3-城镇居民医疗保险,4-商业保险,5-公费医疗,6-自费医疗,7-其它", required = true)
    private Integer payMode;
    @ApiModelProperty(value = "医疗支付方式文本")
    private String payModeText;

    @ApiModelProperty("婚姻状态: 1-已婚,2-未婚,3-单身,4-丧偶")
    private Integer maritalStatus;
    @ApiModelProperty("婚姻状态文本")
    private String maritalStatusText;

    @ApiModelProperty("医保号码")
    private String socialSecurityId;

    @ApiModelProperty("地址")
    private String address;

    @ApiModelProperty("工作单位")
    private String workUnit;

    @ApiModelProperty("民族")
    private String nation;

    @ApiModelProperty("收入水平")
    private String income;

    @ApiModelProperty(value = "身高", required = true)
    private Float height;

    @ApiModelProperty(value = "体重", required = true)
    private Float weight;

    @ApiModelProperty("患者头像图片地址")
    private String avatar;

    @ApiModelProperty("机构编码")
    private String orgCode;

    @ApiModelProperty("家属姓名")
    private String familyName;

    @ApiModelProperty("家属手机号")
    private String familyMobile;

    @ApiModelProperty("家属关系：1-父亲,2-母亲,3-丈夫,4-妻子,5-爷爷,6-奶奶,7-外公,8-外婆,9-儿子,10-女儿,11-亲戚,12-其他")
    private Integer familyRelation;
    @ApiModelProperty("家属关系文本")
    private String familyRelationText;

    @ApiModelProperty(value = "确认是否完成", notes = "1-确认完成, 0-未完成")
    private Integer isFinished = 0;

    @ApiModelProperty(value = "患者二维码")
    private String qrCode;

    @ApiModelProperty(value = "患者体型照片")
    private String patientBodyImage;

    public void parseFromPO(DtrdEntRdArchiveBasic po) {
        isFinished = po.getIsFinished();
    }

    public void parseFromPO(DtrdEntRdArchiveBasicFamily basicFamily) {
        this.setFamilyName(basicFamily.getFamilyName());
        this.setFamilyMobile(basicFamily.getFamilyMobile());
        this.setFamilyRelation(basicFamily.getFamilyRelation());
    }

    public void parseFromPO(DtrdEntRdPatient patient) {
        dataId=patient.getDataId();
        this.setPatientConfirmedDate(patient.getPatientsConfirmedDate());
        this.setPatientModeOnset(patient.getPatientsModeOnset());
        this.setPatientSymptoms(patient.getPatientsSymptoms());
        this.setPatientDesc(patient.getPatientsDescription());
        this.setPatientIdCard(patient.getPatientsIdCard());
        this.setPatientMedicalInsurance(patient.getPatientsMedicalInsurance());
        this.setPatientDiagnostic(patient.getPatientsDiagnostic());
        // 糖尿类型及文本
        Integer diabetisType = patient.getPatientsDiabetisType();
        this.setPatientDiabetisType(diabetisType);
        Constant.DiabetesType constant = Constant.DiabetesType.valueOf(diabetisType);
        assert constant != null;
        this.setPatientDiabetisTypeText(constant.getName());
        this.setPatientDesc(patient.getPatientsDescription());
        // 头像
        this.setAvatar(patient.getPatientsImg());
        this.setProvinceId(patient.getPatientsProvinceId());
        this.setCityId(patient.getPatientsCityId());
        qrCode = patient.getWxOaQrcodeUrl();
    }

    public DtrdEntRdPatient toPoPatient() {
        DtrdEntRdPatient patient = new DtrdEntRdPatient();
        patient.setDataId(this.getPatientId());
        patient.setPatientsName(this.getPatientName());
        patient.setPatientsMobile(this.getPatientMobile());
        patient.setPatientsConfirmedDate(this.getPatientConfirmedDate());
        patient.setPatientsWeight(this.getWeight());
        // 小心 npe
        if (this.getHeight() != null) {
            patient.setPatientsHeight(this.getHeight().intValue());
        }
        patient.setPatientsLocation(this.getAddress());
        patient.setPatientsImg(this.getAvatar());
        patient.setPatientsBirthday(this.getPatientBirth());
        patient.setPatientsProvinceId(this.getProvinceId());
        patient.setPatientsCityId(this.getCityId());
        patient.setPatientsSex(this.getPatientSex());
        patient.setPatientsDescription(this.getPatientDesc());
        patient.setPatientsIdCard(this.getPatientIdCard());
        patient.setPatientsDiagnostic(this.getPatientDiagnostic());
        patient.setPatientsDiabetisType(this.getPatientDiabetisType());
        patient.setPatientsModeOnset(this.getPatientModeOnset());
        patient.setPatientsSymptoms(this.getPatientSymptoms());
        patient.setPatientsMedicalInsurance(this.getPatientMedicalInsurance());
        patient.setPatientsDiagnostic(this.getPatientDiagnostic());
        patient.setDoctorId(doctorId);
        return patient;
    }
}
